<template>
        <view class="content">
            <!-- #ifdef MP-WEIXIN -->
            <top-nav :inner-title="title" :navTip="navTip" is-show-back="true" is-fixed="true" :navH="navH" :n="n" is-white="bg-red-gradient" opacity="1"></top-nav>
            <view :style="{height:navH + 30 + 'px'}"></view>
            <!-- #endif -->
            <view v-for="(item,index) in goodsList" :key="index" class="shop-list-item"  @click='openStore($event)' :data-storeid='item.store_id' :data-categoryId='item.category_id' :data-id='item.id'>
              <view class="shop-info-left">
                  <block v-if='item.disable && item.reserve_status != 1'>
                      <view class='close'></view>
                  </block>
                  <image class="shop-info-img" :src="item.img_path"  lazy-load="true"></image>
              </view>
              <view class="shop-info-detail flex column">
                 
                        <view class="shop-info-detail-name flex">
                            <view class="goods_name ellipsis">{{item.name}}</view>
                            <view class="shop-tags flex">
                                <view class="sales_content green flex" v-if="item.open_oneself == 1">支持自取</view>
                                <view class="sales_content green flex" v-else-if="item.open_oneself == 2">仅支持自取</view>
                                <image v-if="item.icon_tag == 1" class="icon_tag" src="http://img1.birdback.org/a/90/05/90053125f1582b6f6648d64b8d253acb.png" />
                                <image v-if="item.icon_tag == 2" class="icon_tag" src="http://img1.birdback.org/a/36/24/3624da078f7adfb7f650b3840125961e.png" />
                            </view>
                        </view>
                        <view class="shop-info-detail-middle">
                          <view class="shop-info-detail-sales ellipsis">{{item.shop_name}}</view>  
                        </view>
                        <view class="shop-info-detail-middle">
                              <view class="flex left">
                                  <view class="goods_price">¥<text>{{item.price}}</text></view>
                                  <view class="old_price" v-if="item.show_price">{{item.show_price}}元</view>
                                  <view class="goods_discount flex" v-if="item.discount">
                                      <view class="tri"></view>
                                      <view class="re flex">{{item.discount}}折</view>
                                  </view>
                              </view>
                              <view class="or_bt flex">马上抢</view>
                        
                        </view>
                 
              </view>
            </view>
            <view class="no-more" v-if="noMore">更多超值抢购接入中，敬请期待！</view>
        </view>
</template>

<script>
    import uniFly from 'unifly';
	import request from '../../common/request.js';
	import $api_base from '../../api/api_base.js';
	import topNav from '@/template/topnav/index.vue';
    export default {
		components: { topNav },
		data() {
			return {
				goodsList: [],
                add_time: '',
                hasMore: 0,
                isEmpty: true,
                pn: 1,
                pc: 10,
                navH: 0,
                n:0,
                title: '',
                navTip: ' ',
                noMore: false,
                schoolId: 0
			}
		},
		onLoad(options){
			this.navH     = getApp().globalData.navHeight;
            this.n        = getApp().globalData.n;
            this.schoolId = options.schoolId || '16';
            // #ifdef MP-ALIPAY
            uni.setNavigationBarTitle({
              title: '超值抢购'
            })
            // #endif
            this.loadData(false);
        },
		onShow(optons){
			
		},
		methods:{
            loadData: function (isAppend) {
                var pn = this.pn;
                var where = new Object();
                var self = this;
                var school_id = this.schoolId;
                var pc = this.pc;
                $api_base.post($api_base.getGoodsActive,{school_id:school_id, pn: pn, limit: pc}).then(function(res) {
                    let data = res.data;
                    if (data.ok == 1) {
                        if(isAppend){
                            self.goodsList = [...self.goodsList, ...data.list];
                        }else{
                            self.goodsList = data.list;
                        }
                        
                    }
                });
            },
			openStore: function (e) {
			    var storeId = e.currentTarget.dataset.storeid;
			   // #ifdef MP-WEIXIN
			   var categoryId = e.currentTarget.dataset.categoryid || '';
			   // #endif
			   // #ifdef MP-ALIPAY
			   var categoryId = e.currentTarget.dataset.categoryId || '';
			   // #endif
			    var id = e.currentTarget.dataset.id || '';
			    getApp().globalData.scene = null;
			    uni.navigateTo({
			      url: '/pages/goods/goods?storeId=' + storeId + '&sid=index' + '&categoryId=' + categoryId + '&id=' + id ,
			    })
			},
			/**
			 * 页面相关事件处理函数--监听用户下拉动作
			 */
			onPullDownRefresh: function () {
				uni.stopPullDownRefresh();
			},
			/**
			 * 页面上拉触底事件的处理函数
			 */
			onReachBottom: function () {
			  var pn = this.pn;
			  var pc = this.pc;
			  var count = this.goodsList.length;
			  if (pn * pc <= count) {
			      this.pn++;
			      this.loadData(true);
			  } else {
			    this.noMore = true;
			  }
			}
		}
	}
</script>
<style>
  page {
  background-color: #fff;
  }
</style>
<style lang="scss" scoped>
	@import '../../pages/index/index.scss';
    @import 'index.scss';
</style>
